package com.example.common.mapper;

import com.example.common.enetiy.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author qwer3
 * @version 1.0.0
 * @create 2025/10/30 21:40
 */
@Mapper
public interface UserMapper {

    @Insert("""
INSERT INTO sys_user (user_id, username, password, nickname, phone, dormitory, create_time, update_time, operator_id, is_delete) 
VALUES (#{userId}, #{username}, #{password}, #{nickname}, #{phone}, #{dormitory}, now(), now(), null, 0);
""")
    void addUser(User user);

    @Select("""
select * from sys_user where username = #{username} and password = #{password}
""")
    User queryUserByLogin(@Param("username") String username,
                          @Param("password") String password);

    @Select("""
select * from sys_user where username = #{username}
""")
    User queryUserByRegister(@Param("username") String username);


    @Select("""
select * from sys_user where user_id = #{userId} and is_delete = 0
""")
    User queryUserByUserId(String userId);


    // =========================================== 管理端方法 =============================================

    @Update("""
update sys_user set is_delete = 1 where user_id = #{userId}
""")
    void disableSystemUser(String userId);

    @Select("""
select * from sys_user
""")
    List<User> queryAllUser();
}
